package com.xuecheng.media.controller;

import com.xuecheng.api.content.model.qo.QueryCourseModel;
import com.xuecheng.api.media.model.MediaApi;
import com.xuecheng.api.media.model.dto.MediaDTO;
import com.xuecheng.api.media.model.qo.QueryMediaModel;
import com.xuecheng.api.media.model.vo.MediaVO;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.common.domain.response.RestResponse;
import com.xuecheng.common.util.SecurityUtil;
import com.xuecheng.media.convert.MediaConvert;
import com.xuecheng.media.service.MediaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 媒资信息 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
public class MediaController implements MediaApi {

    @Autowired
    private MediaService mediaService;

    @PostMapping("media")
    public MediaDTO createMedia(@RequestBody MediaVO mediaVO) {

        Long companyId = SecurityUtil.getCompanyId();

        MediaDTO mediaDTO = MediaConvert.INSTANCE.vo2dto(mediaVO);
        mediaDTO.setCompanyId(companyId);

        MediaDTO result = mediaService.createMedia(mediaDTO);
        return result;
    }

    /**
     * 分页查询课程基本信息
     *
     * @param params
     * @param model
     * @return
     */
    @PostMapping("media/list")
    public PageVO queryMediaList(PageRequestParams params, @RequestBody QueryMediaModel model) {

        Long companyId = SecurityUtil.getCompanyId();

        PageVO pageVO = mediaService.queryMediaList(params, model, companyId);
        return pageVO;
    }


    /**
     * 根据id查询媒资信息
     * @param mediaId
     * @return
     */
    @GetMapping("l/media/{mediaId}")
    public RestResponse<MediaDTO> getMediaById4s(@PathVariable Long mediaId) {
        return mediaService.getMediaById4s(mediaId);
    }
}
